#include <windows.h>		// Header File For Windows
#include <GL\glew.h>
#include <gl\GL.h>
#include <gl\GLU.h>
#include <cstdlib>
#include <cstdio>
#include "textfile.h"
#ifndef NULL
#define NULL 0
#endif


unsigned int	_glewInit()
{
	return glewInit();
}
void printInfoLog(GLuint obj)
{
    int infologLength = 0;
    int charsWritten  = 0;
    char *infoLog;

	glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB,
                                         &infologLength);

    if (infologLength > 0)
    {
        infoLog = (char *)malloc(infologLength);
        glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
		printf("%s\n",infoLog);
        free(infoLog);
    }
}

GLuint v,f,f2,p;
void setShaders() {

	char *vs = NULL,*fs = NULL,*fs2 = NULL;

	v = glCreateShader(GL_VERTEX_SHADER);
	f = glCreateShader(GL_FRAGMENT_SHADER);
	f2 = glCreateShader(GL_FRAGMENT_SHADER);


	vs = textFileRead("minimal.vert");
	fs = textFileRead("minimal.frag");

	if(NULL== vs || NULL == fs)
	{
		printf("Read shader file failed.");
	}
	const char * vv = vs;
	const char * ff = fs;

	glShaderSource(v, 1, &vv,NULL);
	glShaderSource(f, 1, &ff,NULL);

	free(vs);free(fs);

	glCompileShaderARB(v);
	glCompileShaderARB(f);

	printInfoLog(v);
	printInfoLog(f);
	printInfoLog(f2);

	p = glCreateProgram();
	glAttachShader(p,v);
	glAttachShader(p,f);

	glLinkProgram(p);
	printInfoLog(p);

	glUseProgram(p);




}
